var pageii = null;
var grid = null;
$(function() {
	
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "操作",
			width : "110px",
			renderData : function(rowindex,data, rowdata, column) {
				return "<img class='imgbtn' title='编辑会议' src='" + rootPath + "/images/edit.png' onclick=\"editFun('"+data+"')\"/>&nbsp;&nbsp;&nbsp;&nbsp;" +
						"<img class='imgbtn' title='查看' src='" + rootPath + "/images/view.png' onclick=\"viewFun('"+data+"')\">";
			}
		}, {
			colkey : "name",
			name : "会议名"
		}, {
			colkey : "content",
			name : "会议描述",
			align : "left",
			renderData : function(rowindex,data, rowdata, column) {
				return data.replace(/\n/g,'<br>');
			}
		}, {
			colkey : "imgPath",
			name : "二维码",
			width : '165px',
			renderData : function(rowindex,data, rowdata, column) {
				return "<img height='150px' src='" + data + "'/>";
			}
		}, {
			colkey : "status",
			name : "状态",
			width : "100px",
			renderData : function(rowindex,data, rowdata, column) {
				return "<div class='onoffswitch'>"
						+ "    <input type='checkbox' class='onoffswitch-checkbox' onchange='onoff(" + rowdata.id + ",this.checked)'"
						+ "    id='onoff" + rowindex + "'" + (data==0?"checked":"")
						+ "    ><label class='onoffswitch-label' for='onoff"+rowindex+"'>"
						+ "        <span class='onoffswitch-inner'></span>"
						+ "        <span class='onoffswitch-switch'></span>"
						+ "    </label>"
						+ "</div>";
			}
		}, {
			colkey : "createTime",
			name : "创建时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		}, {
			colkey : "lastOpenTime",
			name : "最后开启时间",
			renderData : function(rowindex,data, rowdata, column) {
				if (data) {
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				} else {
					return "";
				}
			}
		}, {
			colkey : "lastCloseTime",
			name : "最后关闭时间",
			renderData : function(rowindex,data, rowdata, column) {
				if (data) {
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				} else {
					return "";
				}
			}
		}],
		jsonUrl : rootPath + '/meeting/findByPage.shtml',
		checkbox : false
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		$("input[qt=like]").each(function() {
			if ($(this).val().trim() != "") {
				searchParams[$(this).attr("name")] = "%" + $(this).val().trim() + "%";
			}
		});
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addFun").click("click", function() {
		addFun();
	});
	$("#editFun").click("click", function() {
		editFun();
	});
});
function editFun(cbox) {
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "300px" ],
		content : [rootPath + '/meeting/editUI.shtml?id=' + cbox, 'no']
	});
}
function addFun() {
	pageii = layer.open({
		title : "新增",
		type : 2,
		area : [ "600px", "300px" ],
		content : [rootPath + '/meeting/addUI.shtml', 'no']
	});
}

function onoff(id,ischeck){
	var data = CommnUtil.ajax(rootPath + '/meeting/updateStatus.shtml',{'meetingFormMap.id':id,'meetingFormMap.status':(ischeck?0:1)},"json");
	console.info(data+1);
	if (data == "success") {
		grid.loadData();
	} else {
		layer.msg((ischeck?"开启会议":"关闭会议") + '失败！' + data);
	}
}

function viewFun(id) {
	var tb = $("#loadhtml");
	tb.html(CommnUtil.loadingImg());
	tb.load(rootPath+"/meeting/viewMeeting.shtml?id=" + id);
}